//
//  FacebookCocosSDK.swift
//  Game105Client-mobile
//
//  Created by Developer001 on 2025/4/1.
//

import Foundation

import FacebookCore

@objc class FacebookCocosSDK : NSObject, SDKDelegate{
    
    // 静态变量持有单例实例
    @MainActor
    static var instance: FacebookCocosSDK?
    
    var viewController :UIViewController?
    
    @MainActor
    @objc func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        print("@FacebookCocosSDK launched")
        
        FacebookCocosSDK.instance = self
        
        if let window = application.delegate?.window {
            viewController = window?.rootViewController
        }
        
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        
        return true
    }
    
    @objc func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
    }
    
    @MainActor @available(iOS 13.0, *)
    @objc func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let url = URLContexts.first?.url else {
            return
        }
        ApplicationDelegate.shared.application(
            UIApplication.shared,
            open: url,
            sourceApplication: nil,
            annotation: [UIApplication.OpenURLOptionsKey.annotation]
        )
    }
    
}
